package me.mcx.mcx.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import me.mcx.common.annotation.Log;
import me.mcx.common.core.controller.BaseController;
import me.mcx.common.core.domain.AjaxResult;
import me.mcx.common.core.page.TableDataInfo;
import me.mcx.common.enums.BusinessType;
import me.mcx.common.utils.poi.ExcelUtil;
import me.mcx.mcx.domain.McxHonor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import me.mcx.mcx.service.IMcxHonorService;

/**
 * 荣誉墙Controller
 * 
 * @author mcx
 * @date 2024-09-21
 */
@RestController
@RequestMapping("/mcx/honor")
public class McxHonorController extends BaseController
{
    @Autowired
    private IMcxHonorService mcxHonorService;

    /**
     * 查询荣誉墙列表
     */
    @PreAuthorize("@ss.hasPermi('mcx:honor:list')")
    @GetMapping("/list")
    public TableDataInfo list(McxHonor mcxHonor)
    {
        startPage();
        List<McxHonor> list = mcxHonorService.selectMcxHonorList(mcxHonor);
        return getDataTable(list);
    }

    /**
     * 导出荣誉墙列表
     */
    @PreAuthorize("@ss.hasPermi('mcx:honor:export')")
    @Log(title = "荣誉墙", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, McxHonor mcxHonor)
    {
        List<McxHonor> list = mcxHonorService.selectMcxHonorList(mcxHonor);
        ExcelUtil<McxHonor> util = new ExcelUtil<McxHonor>(McxHonor.class);
        util.exportExcel(response, list, "荣誉墙数据");
    }

    /**
     * 获取荣誉墙详细信息
     */
    @PreAuthorize("@ss.hasPermi('mcx:honor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mcxHonorService.selectMcxHonorById(id));
    }

    /**
     * 新增荣誉墙
     */
    @PreAuthorize("@ss.hasPermi('mcx:honor:add')")
    @Log(title = "荣誉墙", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody McxHonor mcxHonor)
    {
        return toAjax(mcxHonorService.insertMcxHonor(mcxHonor));
    }

    /**
     * 修改荣誉墙
     */
    @PreAuthorize("@ss.hasPermi('mcx:honor:edit')")
    @Log(title = "荣誉墙", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody McxHonor mcxHonor)
    {
        return toAjax(mcxHonorService.updateMcxHonor(mcxHonor));
    }

    /**
     * 删除荣誉墙
     */
    @PreAuthorize("@ss.hasPermi('mcx:honor:remove')")
    @Log(title = "荣誉墙", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mcxHonorService.deleteMcxHonorByIds(ids));
    }
}
